import 'package:flutter/material.dart';
import 'package:flutter_ohos/components/MTFoodDetail.dart';

class MTFoodItem extends StatelessWidget {
  const MTFoodItem({Key? key, required this.foodItem}) : super(key: key);

  final Map<String, dynamic> foodItem;
  Widget leftData() {
    return Container(
      margin: EdgeInsets.all(10),
      child: ClipRRect(
        borderRadius: BorderRadius.circular(5),
        child: Image.network(
          foodItem["picture"],
          width: 100,
          height: 100,
          fit: BoxFit.cover,
        ),
      ),
    );
  }

  Widget rightData() {
    return Padding(
      padding: EdgeInsets.only(top: 10, bottom: 10),
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        mainAxisAlignment: MainAxisAlignment.spaceBetween,
        children: [
          Text(
            foodItem["name"],
            style: TextStyle(fontWeight: FontWeight.w600, fontSize: 20),
          ),
          Text('月销量${foodItem["month_saled"]} ${foodItem["like_ratio_desc"]}',
              style: TextStyle(fontWeight: FontWeight.w500, fontSize: 14)),
          Text(foodItem["price"].toString(),
              style: TextStyle(
                  fontWeight: FontWeight.w600,
                  fontSize: 14,
                  color: Colors.amber))
          // Text(),
          // Text(),
          // Text(),
        ],
      ),
    );
  }

  Widget allData() {
    return Row(
      children: [leftData(), rightData()],
    );
  }

  @override
  Widget build(BuildContext context) {
    return Row(
      crossAxisAlignment: CrossAxisAlignment.start,
      children: [
        GestureDetector(
          onTap: () {
            // Navigator.push(context,
            //     MaterialPageRoute(builder: (BuildContext context) {
            //   return MTFoodDetail();
            // }));
            Navigator.pushNamed(context, '/tabs');
          },
          child: allData(),
        )
      ],
    );
  }
}
